package gdou.gym.sys.cofig;

import gdou.gym.sys.order.RemainInterceptor;
import gdou.gym.sys.resolve.PageResolve;
import gdou.gym.sys.safe.AuthenticationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class ServletConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor()).addPathPatterns("/**").excludePathPatterns("/*/login");
        registry.addInterceptor(remainInterceptor()).addPathPatterns("/user/order");
    }


    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(pageResolve());
    }

    @Bean
    public PageResolve pageResolve() {
        return new PageResolve();
    }

    @Bean
    public AuthenticationInterceptor authenticationInterceptor() {
        return new AuthenticationInterceptor();
    }

    @Bean
    public RemainInterceptor remainInterceptor() {
        return new RemainInterceptor();
    }


}
